All Questions
11 questions
1vote
4answers
11kviews
C++: Is a pointer to a vector going to cause memory issues?
I started to write a function which had a pointer to a vector as a parameter so that it could modify that vector to output results (as the actual return value was an error code), when I started to ...
5votes
1answer
7kviews
Why do we need to specify the type of data a pointer will hold, if all pointers are the same [duplicate]
Why do we need to specify the type of the data whose address, a pointer will hold, if all pointers are the same. Since all pointers store addresses. Also, the amount of space a pointer will require in ...
0votes
2answers
2kviews
What is the safest practice in handling QWidget pointer lifespan in a QObject oriented environment?
Consider the following constructor: NetworkTools::NetworkTools(QObject *parent) : QObject(parent) { view = new QWebEngineView(); view->setParent(parent); // Produces an error, shown below. ...
-1votes
1answer
2kviews
Why is it possible to access an array out of bounds with negative indexes much further than with positive indexes?
I have written two small programs in which I declare a very small array. Then I try to access values out of bounds. The interesting thing I noticed that when I try to decrement the index I can ...
26votes
3answers
8kviews
Why does a long int take 12 bytes on some machines?
I noticed something strange after compiling this code on my machine: #include <stdio.h> int main() { printf("Hello, World!\n"); int a,b,c,d; int e,f,g; long int h; ...
2votes
5answers
2kviews
What value does the byte pointed by null pointer have?
I know that long time ago computer scientists decided to treat all pointers to memory cell of address 0 as NULL. However, the memory cell at that address does exists after all, right? In that case, ...
1vote
1answer
203views
Static memory idiom
I am on a micro controller (which means I can only have static memory allocation) and I am trying to work with inheritance..... Suppose I have a abstract class Image and an abstract class Font. An ...
7votes
4answers
924views
Autoreleasing objects in Reference Counting Systems
I'm experimenting a bit in C and I'm trying to implement my own Reference Counting System. I've mainly worked with Objective-C in the past but AFAIK autoreleasing objects is something that is unique ...
5votes
6answers
8kviews
What are memory addresses? [closed]
I have more or less 0 knowledge in low-level topics, so forgive my possible ignorance. I know that in languages such as C, pointers hold 'memory addresses', i.e. strings (or binary data?) written in ...
-2votes
4answers
2kviews
C simple arrays and pointers question
So here's the confusion, let's say I declare an array of characters char name[3] = "Sam"; and then I declare another array but this time using pointers char * name = "Sam"; What's the difference ...
6votes
2answers
3kviews
Smart Pointers inside class vs Normal Pointers with Destructor
Regarding pointers which are members of classes. Should they be of a smart pointer type or is it enough to simply deal with them in the destructor of the class they are contained in?